package qnb.controller;

import java.io.IOException;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/down")
public class ExcelDown {
	// 修改
		@RequestMapping("/excel")
		public void downexcel(HttpServletResponse response) throws IOException {
			ServletOutputStream oup=response.getOutputStream();
			 response.setHeader( "Content-Disposition", "attachment;filename="  + new String( "aaa我是excela.xlsx".getBytes("utf-8"), "ISO8859-1" ) );
			 
			try (HSSFWorkbook wb = new HSSFWorkbook()) {
				
				HSSFSheet sheet = wb.createSheet("值日表");
				HSSFRow row = sheet.createRow(0);//第1行
				
				HSSFCell cell = row.createCell(0);
				cell.setCellValue("ABC");
				cell = row.createCell(1);
				cell.setCellValue("EEE");
				cell = row.createCell(2);
				cell.setCellValue("CCC");
				
				row = sheet.createRow(1);//第2行
				cell = row.createCell(0);
				cell.setCellValue("1");
				cell = row.createCell(1);
				cell.setCellValue("2");
				cell = row.createCell(2);
				cell.setCellValue("3");
				wb.write(oup);

			}
			
		}
}
